package com.apkfuns.jsbridge.slice;

import com.apkfuns.jsbridge.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button webViewButton = (Button) findComponentById(ResourceTable.Id_btn_webView);

        webViewButton.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();

                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName("com.apkfuns.jsbridge.view.WebViewAbility")
                        .build();

                intent.setOperation(operation);
                startAbility(intent);
            }
        });
        Button customWebViewButton = (Button) findComponentById(ResourceTable.Id_btn_custom_webView);
        customWebViewButton.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName("com.apkfuns.jsbridge.view.CustomWebViewAbility")
                        .build();

                intent.setOperation(operation);
                startAbility(intent);
            }
        });
        Button fragmentWebViewButton = (Button) findComponentById(ResourceTable.Id_btn_fragment_webView);
        fragmentWebViewButton.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName("com.apkfuns.jsbridge.view.CustomFragmentAbility")
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });
    }

}
